﻿using StarPizza.Model.BaseModel;
using StarPizza.Model.User;
using StarPizza.ViewModel.ClientSystem;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarPizza.ViewModel.ManagerSystem
{
    class ClientAdministrator
    {
        UserSpace userSpace;
        StarDataDataContext db;
        public ClientAdministrator(StarDataDataContext db, UserSpace userSpace)
        {
            this.db = db;
            this.userSpace = userSpace;
            ClientVMs = new ObservableCollection<ClientVM>();
            foreach (var client in userSpace.Clients)
            {
                AddClient(client);
            }
            userSpace.ClientRegistrated += AddClient;
        }

        public ObservableCollection<ClientVM> ClientVMs { get; set; }
        void AddClient(Client client)
        {
            ClientVMs.Add(new ClientVM(client));
        }
        public void SaveChanges()
        {
            foreach (var clientVM in ClientVMs)
            {
                clientVM.UpdateModel();
            }
            Utility.TrySubmitChanges(db);
        }
    }
}
